var WebSockectServer = require('ws').Server
    , wss = new WebSockectServer({port:8887});

wss.on('connection', function(ws) {
    /*ws.on('message', function(message) {
        ws.send(Date.now().toString());
        console.log('received: %s', message);
    });*/
    var id = setInterval(function() {
        console.log('sending...');        
        ws.send(('{"time":"' + Date.now().toString() + '"}').toString(), function() {});
    }, 1000);

    //ws.send(Date.now().toString());    

    wss.on('close', function() {
        console.log('Connection closed...');
        clearInterval(id);
    });    
});

wss.on('message', function(message) {
    console.log('Message recevied...');  
});